package org.lex.dbq.view.profile;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.lex.dbq.model.service.ServiceFactory;

public class ProfileDialog extends Dialog {
	public static void main(String[] args) {
		ProfileDialog d = new ProfileDialog((Shell) null);
		d.open();
	}

	public ProfileDialog(Shell parentShell) {
		super(parentShell);
		this.setBlockOnOpen(true);
		this.setShellStyle(SWT.MAX | SWT.RESIZE);
	}

	@Override
	protected void configureShell(Shell shell) {
		super.configureShell(shell);
		shell.setText("Profile");
	}

	@Override
	protected Control createDialogArea(Composite parent) {
		TabFolder folder = new TabFolder(parent, SWT.NONE);
		folder.setLayoutData(new GridData(GridData.FILL_BOTH));

		this.createDriverTab(folder);
		this.createTemplateTab(folder);
		this.createSessionTab(folder);
		return parent;
	}

	private TabItem createDriverTab(TabFolder folder) {
		TabItem tab = new TabItem(folder, SWT.NONE);
		tab.setText("Drivers");
		Table table = TableUtils.createTable(folder, ServiceFactory.getDriverService().getAllObjects());
		tab.setControl(table);
		return tab;
	}

	private TabItem createTemplateTab(TabFolder folder) {
		TabItem tab = new TabItem(folder, SWT.NONE);
		tab.setText("Templates");
		Table table = TableUtils.createTable(folder, ServiceFactory.getTemplateService().getAllObjects());
		tab.setControl(table);
		return tab;
	}

	private TabItem createSessionTab(TabFolder folder) {
		TabItem tab = new TabItem(folder, SWT.NONE);
		tab.setText("Sessions");
		Table table = TableUtils.createTable(folder, ServiceFactory.getSessionService().getAllObjects());
		tab.setControl(table);
		return tab;
	}
}
